package com.ruoyi.webInfor.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.webInfor.domain.CompanyInformation;
import com.ruoyi.webInfor.service.ICompanyInformationService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 公司信息Controller
 * 
 * @author ruoyi
 * @date 2021-12-20
 */
@RestController
@RequestMapping("/web/comInfor")
public class CompanyInformationController extends BaseController
{
    @Autowired
    private ICompanyInformationService companyInformationService;

    /**
     * 查询公司信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CompanyInformation companyInformation)
    {
        startPage();
        List<CompanyInformation> list = companyInformationService.selectCompanyInformationList(companyInformation);
        return getDataTable(list);
    }

    /**
     * 导出公司信息列表
     */
    @Log(title = "公司信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CompanyInformation companyInformation)
    {
        List<CompanyInformation> list = companyInformationService.selectCompanyInformationList(companyInformation);
        ExcelUtil<CompanyInformation> util = new ExcelUtil<CompanyInformation>(CompanyInformation.class);
        util.exportExcel(response, list, "公司信息数据");
    }

    /**
     * 获取公司信息详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(companyInformationService.selectCompanyInformationById(id));
    }

    /**
     * 新增公司信息
     */
    @Log(title = "公司信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CompanyInformation companyInformation)
    {
        companyInformation.setId(IdUtils.fastSimpleUUID());
        return toAjax(companyInformationService.insertCompanyInformation(companyInformation));
    }

    /**
     * 修改公司信息
     */
    @Log(title = "公司信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CompanyInformation companyInformation)
    {
        return toAjax(companyInformationService.updateCompanyInformation(companyInformation));
    }

    /**
     * 删除公司信息
     */
    @Log(title = "公司信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(companyInformationService.deleteCompanyInformationByIds(ids));
    }
}
